package com.kalvin.kvf.modules.xhs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.xhs.entity.LoginUser;
import com.kalvin.kvf.modules.xhs.service.XhsLoginUserService;

import java.util.List;


/**
 * <p>
 * 服务端登录小红书账号 前端控制器
 * </p>
 * @since 2023-12-01 11:32:07
 */
@RestController
@RequestMapping("xhs/loginUser")
public class XhsLoginUserController extends BaseController {

    @Autowired
    private XhsLoginUserService loginUserService;

    @RequiresPermissions("xhs:loginUser:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("xhs/loginUser");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("xhs/loginUser_edit");
        LoginUser loginUser;
        if (id == null) {
            loginUser = new LoginUser();
        } else {
            loginUser = loginUserService.getById(id);
        }
        mv.addObject("editInfo", loginUser);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(LoginUser loginUser) {
        Page<LoginUser> page = loginUserService.listLoginUserPage(loginUser);
        return R.ok(page);
    }

    @RequiresPermissions("xhs:loginUser:add")
    @PostMapping(value = "add")
    public R add(LoginUser loginUser) {
        loginUserService.save(loginUser);
        return R.ok();
    }

    @RequiresPermissions("xhs:loginUser:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List<Long> ids) {
        loginUserService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("xhs:loginUser:edit")
    @PostMapping(value = "edit")
    public R edit(LoginUser loginUser) {
        loginUserService.updateById(loginUser);
        return R.ok();
    }

    @RequiresPermissions("xhs:loginUser:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        loginUserService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(loginUserService.getById(id));
    }

}

